package com.web.controller;

import com.alibaba.fastjson2.JSON;

import com.web.entity.PageVO;
import com.web.entity.ResponseResult;
import com.web.service.StudentService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import javax.annotation.Resource;
import java.io.IOException;

@WebServlet("/findStudentPage")
public class FindStudentPageServlet extends HttpServlet {

    @Resource
    private StudentService studentService;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String current = req.getParameter("current");
        String pageSize = req.getParameter("pageSize");
        int cur = 1;
        if(current != null){
            cur = Integer.parseInt(current);
        }
        int pSize = 10;
        if(pageSize != null){
            pSize = Integer.parseInt(pageSize);
        }
        //设置响应类型
        resp.setContentType("application/json;charset=UTF-8");
        PageVO page = studentService.findStudentPage(cur,pSize);
        resp.getWriter().write(JSON.toJSONString(new ResponseResult(200,"OK",page)));

    }
}
